var result = [];// [19000, 826.3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

$(function(){
    $(document).bind('contextmenu',function (e) {
        e.preventDefault();
        $('#right_menu').menu('show',{
            left:e.pageX,
            top:e.pageY
        });
    });
    $.ajax({
        type:"get",
        url: basePath + "report/expenseColumnReport",
        beforeSend: function(request) {
            request.setRequestHeader("header", localStorage.getItem("token"));
        },
        data:{},
        async:false,
        cache:true,
        dataType: "json", //this is important
        success:function(data) {
            //迭代，把异步获取的数据放到数组中
            $.each(data,function(i,d){
                result.push([d.value]);
            });
        },
        error : function(data) {
            alert("error:" + data);
        }
    });

    Highcharts.chart('container',{
        chart: {
            type: 'column'
        },
        title: {
            text: '2025年月支出'
        },
        subtitle:{
            text:'点击右键查看月平均消费'
        },
        xAxis: {
            categories: [
                '一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'
            ],
            crosshair: true
        },
        yAxis: {
            min: 0,
            title: {
                text: '月支出 (元)'
            }
        },
        tooltip: {
            // head + 每个 point + footer 拼接成完整的 table
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y:.2f} 元</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                borderWidth: 0
            }
        },
        series: [{
            name: '当月支出',
            data: result
        }]
    });
});

function showAvg() {
    $.ajax({
        type:"get",
        url: basePath + "report/getAvgExpense",
        beforeSend: function(request) {
            request.setRequestHeader("header", localStorage.getItem("token"));
        },
        data:{},
        async:false,
        cache:true,
        dataType: "json", //this is important
        success:function(data) {
            $.messager.alert('SUCCESS',data.data,'SUCCESS');
        },
        error : function(data) {
            alert("error:" + data);
        }
    });
}